<?php
require_once('../phplib/include.inc.php');

class DoDeleteUser{
	public function DoDelete(){
		Util::ValidateRight(1);
		if(!isset($_REQUEST['uid'])) PageBase::Error('非法访问.');
		$uid = intval($_REQUEST['uid']);
		/* @var $db DbMySQL */
		if($uid == intval(Auth::GetData('uid'))) PageBase::Error('您不能把自己删除掉.');
		$db = getDb();
		$db->connect();
		$uname = $db->fetchScalar("SELECT uname FROM user_t WHERE uid=$uid");
		$re = $db->fetch("SELECT * FROM right_t WHERE uid<>$uid AND rid=1");
		if(count($re) < 1){
			PageBase::Error('该用户是目前仅有的有管理用户权限的管理员，不能删除.');
		}
		$db->startTrans();
		$re = $db->execute('DELETE FROM right_t WHERE uid='.$uid);
		if($re === false){
			$db->rollbackTrans();
			PageBase::Error('删除权限时出错，未知错误，请与技术人员联系');
		}
		$re = $db->execute("DELETE FROM user_t WHERE uid=$uid");
		if($re === false){
			$db->rollbackTrans();
			PageBase::Error('删除用户时出错，未知错误，请与技术人员联系');
		}
		$db->commitTrans();
		Util::AddLog("删除用户： $uname , 该用户的id为: $uid ");
		PageBase::Go('../home/useradmin.php');
	}
}
$dodeleteuser = new DoDeleteUser();
$dodeleteuser->DoDelete();
?>